import { defineStore } from "pinia";
import { store } from '@/store';
import type { FormSchema } from "@/components/Form";
import { cloneDeep } from "lodash-es";

interface SupplyDemandState {
  formItemListCache: FormSchema[] | null
}

const createState = (): SupplyDemandState => ({
  formItemListCache: null
});


export const useSupplyDemandStore = defineStore({
  id: 'supplyDemand',
  state: () => createState(),
  getters: {
    getFormItemListCache: (state) => cloneDeep(state.formItemListCache)
  },
  actions: {
    /** 设置表单缓存数据 */
    setFormItemListCache(list: FormSchema[]) {
      this.formItemListCache = list
    },
    /** 清空表单缓存数据 */
    clearFormItemListCache() {
      this.formItemListCache = null
    }
  }
})

export function useActivityWithOut() {
  return useSupplyDemandStore(store);
}